<template>
  <div class="mine-tools" flex>
    <div class="entry-item" @click="toolsClick(tool.url)" v-for="(tool, index) in toolsList" :key="index">
      <image class="entry-item-icon" :src="tool.icon" />
      <div class="entry-item-label">{{ tool.label }}</div>
    </div>


  </div>
</template>


<script setup lang="ts">
import { distribution, applyDistribution } from "@/api/goods";
interface ToolRule {
  label: string,
  icon: string,
  url: string
}

const toolsList = ref<Array<ToolRule>>([
  {
    label: "地址管理",
    icon: "/static/mine/myaddress.png",
    url: "/pages/mine/address/manager"
  },
  {
    label: "我的足迹",
    icon: "/static/mine/logistics.png",
    url: "/pages/mine/tracks"
  },
  {
    label: "评价中心",
    icon: "/static/mine/feedback.png",
    url: "/pages/mine/evaluation/center"
  },
  // {
  //   label: "我的消息",
  //   icon: "/static/mine/mycommit.png",
  //   url: "/pages/mine/message/index"
  // },
  {
    label: "我的关注",
    icon: "/static/mine/myfavorite.png",
    url: "/pages/mine/collect"
  },
  {
    label: "我的积分",
    icon: "/static/mine/mypoint.png",
    url: "/pages/mine/point"
  },
  {
    label: "我的分销",
    icon: "/static/mine/distribution.png",
    url: "/pages/mine/distribution/index"
  },
  {
    label: "我的投诉",
    icon: "/static/mine/shensu.png",
    url: "/pages/mine/sue/list"
  },
  {
    label: "优惠券",
    icon: "/static/mine/mycoupon.png",
    url: "/pages/mine/coupon/achieved"
  },
  {
    label: "每日签到",
    icon: "/static/mine/sign.png",
    url: "/pages/mine/signIn"
  },
  {
    label: "领券中心",
    icon: "/static/mine/couponcenter.png",
    url: "/pages/promotions/coupon/center"
  },
  {
    label: "砍价记录",
    icon: "/static/mine/kanjia.png",
    url: "/pages/promotions/mass-bargain/bargained"
  },
  // {
  //   label: "意见反馈",
  //   icon: "/static/mine/feedback.png",
  //   url: "/pages/mine/feedback"
  // },
  {
    label: "安全中心",
    icon: "/static/mine/anquanzhongxin.png",
    url: "/pages/mine/security-control"
  },
  {
    label: "关于",
    icon: "/static/mine/pointgift.png",
    url: "/pages/mine/shopAbout"
  },
  // {
  //   label: "店铺入驻",
  //   icon: "/static/mine/feedback.png",
  //   url: "/pages/mine/address/addressManage"
  // },
  // {
  //   label: "设置",
  //   icon: "/static/mine/setting.png",
  //   url: "/pages/mine/setting"
  // },
  
])

function toolsClick(url: string) {
  if (url === '/pages/mine/distribution/index') {
    // 我的分销
    distribution().then((res) => {
      if (res.data.result) {
        let type = res.data.result.distributionStatus;
        if (type == "PASS") {
          uni.navigateTo({ url: "/pages/mine/distribution/index" });
        } else if (type == "REFUSE") {
          uni.navigateTo({ url: "/pages/mine/distribution/auth" });
        } else if (type == "RETREAT") {
          uni.showModal({
            content: "您的分销资格已被清退。请联系管理员",
            confirmText: "申诉",
            cancelText: "取消",
            success: (callback) => {
              if (callback.confirm) {
                applyDistribution().then((res) => {
                  if (res.data.success) {
                    uni.showToast({ title: "申诉成功!", duration: 2000, icon: "none" });
                  }
                });
              }
            },
          });
        } else if (type == "APPEAL") {
          uni.showToast({ title: "您的申诉正在审核", duration: 2000, icon: "none", });
        } else {
          uni.showToast({ title: "您的信息正在审核", duration: 2000, icon: "none", });
        }
      } else if (!res.data.success && res.data.code == 22000) {
        uni.showToast({ title: "分销功能暂未开启", duration: 2000, icon: "none", });
      } else {
        // 没有资格申请 先去实名认证
        uni.navigateTo({ url: "/pages/mine/distribution/auth", });
      }
    });
  } else {
    uni.navigateTo({ url })
  }
}

</script>

<style scoped lang="scss">
.mine-tools {
  background: #fff;
  box-shadow: 6rpx 10rpx 24rpx rgba(126, 126, 126, 0.1);
  margin: 20rpx 0;
  border-radius: 24rpx;
  padding: 32rpx 16rpx;
  flex-wrap: wrap;

}

.entry-item {
  gap: 0rpx 20rpx;
  width: 20%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 170rpx;

  >.entry-item-icon {
    width: 50rpx;
    height: 50rpx;
    margin-bottom: 20rpx;

  }

  >.entry-item-label {
    font-size: 24rpx;
  }
}
</style>
